package com.hyl.infrastructure.dcc;

import com.hyl.types.annotations.DCCValue;
import com.hyl.types.common.Constants;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @author hyl
 * @description 动态配置服务
 * @create 2025-06-19 15:34
 */
@Service
public class DCCService {

    @DCCValue("downgradeSwitch:0")
    private String downgradeSwitch;
    @DCCValue("cutRange:100")
    private String cutRange;
    @DCCValue("scBlacklist:s02c02")
    private String scBlacklist;
    public boolean isDowngradeSwitch(){
        return "1".equals(downgradeSwitch);
    }

    public boolean isCutRange(String userId){
        //计算哈希码的绝对值
        int hashCode = Math.abs(userId.hashCode());

        //读取最后两位
         int lastTwoDigits = hashCode % 100;

         //判断时候在切量范围之内
        if (lastTwoDigits <= Integer.parseInt(cutRange)){
            return true;
        }
        return false;

    }


    public boolean isSCBlackIntercept(String source, String channel) {
        List<String> list = Arrays.asList(scBlacklist.split(Constants.SPLIT));
        return list.contains(source + channel);
    }
}
